﻿var deleteNodeId;

Telerik.Web.UI.RadWindow.prototype.oldClose = Telerik.Web.UI.RadWindow.prototype.close;

Telerik.Web.UI.RadWindow.prototype.close = function(arg) {
    if (this.get_name() == 'deleteNodeWindow') {
        deleteNodeWindowCallback(this, arg);
    }
    else {
        this.oldClose(arg);
    }
}

function openDeleteNodeWindow(nodeID) {
    deleteNodeId = nodeID;
    radopen('/medianamik/modalwindows/DeleteNodeWindow.aspx?nodeid=' + nodeID + '&culturename=<%= CurrentEditionCulture.Name %>', 'deleteNodeWindow');
}

function deleteNodeWindowCallback(radWindow, returnValue) {
    Medianamik.UI.Services.LockWebService.Unlock(deleteNodeId, function() { closeDeleteNodeWindow(); }, function() { closeDeleteNodeWindow(); });

    if (returnValue && returnValue.mustReload) {
        $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequest("DeleteNodeWindowCallback");
    }
}

function closeDeleteNodeWindow() {
    var oManager = GetRadWindowManager();
    var oWnd = oManager.GetWindowByName('deleteNodeWindow');
    oWnd.oldClose();
}